let WebSocketServer = require("ws").Server;
let wss = new WebSocketServer({port:9000});
let clientMap = new Object();
var i = 0;
function broadcast(msg,ws){
    for(var key in clientMap){
        clientMap[key].send(ws.name+"说"+msg);
    }
}
wss.on("connection",function(ws){
    console.log(ws+"上线");
    ws.name = i++;
    clientMap[ws.name] = ws;
    ws.on("message",function(message){
        broadcast(message,ws)
    })
    ws.on("close",function(){
        console.log("离开");
    })
})